package com.chouren.goandroid.util;

import java.io.File;

import android.content.Context;

public class FileUtil {
	/**
	 * SD卡是否挂载
	 */
	public static boolean isSDCardMonted() {
		boolean ret = false;
		
		String status = android.os.Environment.getExternalStorageState();
		if(android.os.Environment.MEDIA_MOUNTED.equals(status)) {
			ret = true;
		}
		
		return ret;
	}
	
	/**
	 * 得到应用缓存目录
	 */
	public static File getAppPath(Context context) {
		return context.getFilesDir();
	}
	
	/**
	 * 截取url路径中的文件名
	 */
	public static String getFileNameFromUrl(String url) {
		int index = url.lastIndexOf("\\");
		if(index != -1) {
			return url.substring(index + 1);
		}
		return "";
		
	}
	
	/**
	 * 得到SD卡根目录
	 * @return		SD卡根目录，如果未挂载，返回null
	 */
	public static File getSDCardRoot() {
		if(isSDCardMonted()) {
			return android.os.Environment.getExternalStorageDirectory();
		}
		return null;
	}
}
